interface IPerson {
  name: string;
  age: number;
  frined?: {
    name: string;
  };
}

const info: IPerson = {
  name: "why",
  age: 18,
};

//访问时可以用可选连
console.log(info.frined?.name);

//但是赋值时有两种方法
//解决方法1：类型缩小
if (info.frined) {
  info.frined.name = "朱浩然";
}

//解决方法2:非空类型断言,强制告诉info.frined有值，慎重使用
info.frined!.name = "zhuhaoran";
